unit Class_SQLY;

interface
uses
  Classes,SysUtils;

type
  TSQLY=class(TObject)
  public
    class function ADD_GKX_CORD:string;
    class function ADD_PK_GKX_CORD:string;

    class function ADD_GKX_TYPE:string;
    class function ADD_PK_GKX_TYPE:string;
    class function ADD_FK_GKX_TYPE_RF_GKX_CORD:string;

    class function ADD_GKX_GKJG:string;
    class function ADD_PK_GKX_GKJG:string;

    class function ADD_GKX_GKJG_FL:string;
    class function ADD_PK_GKX_GKJG_FL:string;
    class function ADD_FK_GKX_GKJG_FL_RF_GKX_GKJG:string;

    class function ADD_GKX_GKJL:string;
    class function ADD_PK_GKX_GKJL:string;

    class function ADD_GKX_GKJL_EL:string;
    class function ADD_PK_GKX_GKJL_EL:string;
    class function ADD_FK_GKX_GKJL_EL_RF_GKX_GKJL:string;

    class function ADD_GKX_GKJL_FL:string;
    class function ADD_PK_GKX_GKJL_FL:string;
    class function ADD_FK_GKX_GKJL_FL_RF_GKX_GKJL_EL:string;

    class function ADD_GKX_GKJG_ADD_PKEY_CHCK:string;
    class function UPDATE_GKX_GKJG_SET_PKEY_CHCK_EQUAL_ONE:string;
    class function ADD_GKX_GKJG_ADD_FKEY_CHCK:string;

    class function ADD_GKX_CACH_DATA:string;
    class function ADD_PK_GKX_CACH_DATA:string;
  end;

implementation

{ TSQLY }

class function TSQLY.ADD_FK_GKX_GKJG_FL_RF_GKX_GKJG: string;
begin
  Result:='ALTER TABLE GKX_GKJG_FL ADD CONSTRAINT FK_GKX_GKJG_FL_RF_GKX_GKJG FOREIGN KEY (UNIT_LINK,GKJG_IDEX) REFERENCES GKX_GKJG (UNIT_LINK,GKJG_IDEX) ON DELETE CASCADE ON UPDATE CASCADE';
end;

class function TSQLY.ADD_FK_GKX_GKJL_EL_RF_GKX_GKJL: string;
begin
  Result:='ALTER TABLE GKX_GKJL_EL ADD CONSTRAINT FK_GKX_GKJL_EL_RF_GKX_GKJL FOREIGN KEY (UNIT_LINK,GKJG_IDEX,GKJL_IDEX) REFERENCES GKX_GKJL (UNIT_LINK,GKJG_IDEX,GKJL_IDEX) ON DELETE CASCADE ON UPDATE CASCADE';
end;

class function TSQLY.ADD_FK_GKX_GKJL_FL_RF_GKX_GKJL_EL: string;
begin
  Result:='ALTER TABLE GKX_GKJL_FL ADD CONSTRAINT FK_GKX_GKJL_FL_RF_GKX_GKJL_EL FOREIGN KEY (GKJG_IDEX, UNIT_LINK, GKJL_IDEX, GKJL_FLID) REFERENCES GKX_GKJL_EL (GKJG_IDEX, UNIT_LINK, GKJL_IDEX, GKJL_FLID) ON DELETE CASCADE  ON UPDATE CASCADE';
end;

class function TSQLY.ADD_FK_GKX_TYPE_RF_GKX_CORD: string;
begin
  Result:='ALTER TABLE GKX_TYPE ADD CONSTRAINT FK_GKX_TYPE_RF_GKX_CORD FOREIGN KEY (UNIT_LINK,CORD_IDEX) REFERENCES  GKX_CORD (UNIT_LINK,CORD_IDEX) ON DELETE CASCADE  ON UPDATE CASCADE';
end;

class function TSQLY.ADD_GKX_CACH_DATA: string;
begin
  Result:='CREATE TABLE GKX_CACH_DATA'
       +'    ('
       +'    CACH_IDENTITY VARCHAR(50) NOT NULL,'
       +'    CACH_IDEX INT NOT NULL,'
       +'    CACH_NAME VARCHAR(50) NULL,'
       +'    MAST_CODE VARCHAR(50) NULL,'
       +'    MASTER_DATA TEXT NULL,'
       +'    DETAIL_DATA TEXT NULL'
       +')';
end;

class function TSQLY.ADD_GKX_CORD: string;
begin
  Result:='CREATE TABLE GKX_CORD ('
         +'    UNIT_LINK VARCHAR (50)  NOT NULL ,'
         +'    CORD_IDEX INT NOT NULL ,'
         +'    CORD_CODE VARCHAR (50) NULL ,'
         +'    CORD_NAME VARCHAR (200) NULL ,'
         +'    CORD_MEMO VARCHAR (200) NULL ,'
         +'    CORD_ORDR INT NULL,'
         +'    CORD_TYPE VARCHAR(50) NULL,'
         +'    CODE_RULE VARCHAR(50) NULL,'
         +'    WITH_DASH INT NULL,'
         +'    WITH_ATTR INT NULL'
         +')';
end;

class function TSQLY.ADD_GKX_GKJG: string;
begin
  Result:='CREATE TABLE GKX_GKJG'
         +'    ('
         +'    UNIT_LINK VARCHAR(20) NOT NULL,'
         +'    GKJG_IDEX INT NOT NULL,'
         +'    GKJG_NAME VARCHAR(200) NULL,'
         +'    GKJG_MEMO VARCHAR(200) NULL'
         +')';
end;

class function TSQLY.ADD_GKX_GKJG_ADD_FKEY_CHCK: string;
begin
  Result:='ALTER TABLE GKX_GKJG ADD FKEY_CHCK INT NULL';
end;

class function TSQLY.ADD_GKX_GKJG_ADD_PKEY_CHCK: string;
begin
  Result:='ALTER TABLE GKX_GKJG ADD PKEY_CHCK INT NULL';
end;

class function TSQLY.ADD_GKX_GKJG_FL: string;
begin
  Result:='CREATE TABLE GKX_GKJG_FL'
         +'    ('
         +'    UNIT_LINK            VARCHAR(20)          NOT NULL,'
         +'    GKJG_IDEX            INT                  NOT NULL,'
         +'    GKJG_FLID            INT                  NOT NULL,'
         +'    GKJG_FLBH            INT                  NULL,'
         +'    GKJG_FLMC            VARCHAR(200)         NULL,'
         +'    GKJG_FLLX            INT                  NULL,'
         +'    GKJG_FLDQ            INT                  NULL,'
         +'    GKJG_FLKD            INT                  NULL,'
         +'    GKJG_FLLJ            INT                  NULL,'
         +'    GKJG_FLGQ            INT                  NULL,'
         +'    MAJOR_KEY            INT                  NULL,'
         +'    EMPTY_KEY            INT                  NULL,'
         +'    CORD_IDEX            INT                  NULL,'
         +'    CORD_ATTR            INT                  NULL,'
         +'    VIEW_CODE            VARCHAR(50)          NULL'
         +')';
end;

class function TSQLY.ADD_GKX_GKJL: string;
begin
  Result:='CREATE TABLE GKX_GKJL'
         +'    ('
         +'    UNIT_LINK            VARCHAR(20)          NOT NULL,'
         +'    GKJG_IDEX            INT                  NOT NULL,'
         +'    GKJL_IDEX            INT                  NOT NULL,'
         +'    GKJL_MEMO            VARCHAR(200)         NULL,'
         +'    GKJL_LOAD            INT                  NULL'
         +')';
end;

class function TSQLY.ADD_GKX_GKJL_EL: string;
begin
  Result:='CREATE TABLE GKX_GKJL_EL'
         +'    ('
         +'    GKJG_IDEX            INT                  NOT NULL,'
         +'    UNIT_LINK            VARCHAR(20)          NOT NULL,'
         +'    GKJL_IDEX            INT                  NOT NULL,'
         +'    GKJL_FLID            INT                  NOT NULL,'
         +'    GKJL_DJLX            INT                  NULL,'
         +'    MAJOR_KEY            VARCHAR(500)         NULL,'
         +'    IMPT_DATE            INT                  NULL,'
         +'    IMPT_TYPE            INT                  NULL,'
         +'    GKJL_LOAD            INT                  NULL,'
         +'    IS_DEALED            INT                  NULL'
         +')';
end;

class function TSQLY.ADD_GKX_GKJL_FL: string;
begin
  Result:='CREATE TABLE GKX_GKJL_FL'
         +'    ('
         +'    GKJG_IDEX            INT                  NOT NULL,'
         +'    UNIT_LINK            VARCHAR(20)          NOT NULL,'
         +'    GKJL_IDEX            INT                  NOT NULL,'
         +'    GKJL_FLID            INT                  NOT NULL,'
         +'    GKJG_FLID            INT                  NOT NULL,'
         +'    DATA_DOUB            MONEY                NULL,'
         +'    DATA_TEXT            VARCHAR(100)         NULL,'
         +'    DATA_MEMO            VARCHAR(2048)        NULL'
         +')';
end;

class function TSQLY.ADD_GKX_TYPE: string;
begin
  Result:='CREATE TABLE GKX_TYPE ('
         +'    UNIT_LINK VARCHAR (50)  NOT NULL ,'
         +'    CORD_IDEX INT NOT NULL ,'
         +'    TYPE_IDEX INT NOT NULL ,'
         +'    TYPE_CODE VARCHAR (50)  NULL ,'
         +'    TYPE_PREV VARCHAR (50)  NULL ,'
         +'    TYPE_LEVL INT NULL ,'
         +'    TYPE_LINK VARCHAR (50)  NULL ,'
         +'    TYPE_NAME VARCHAR (50)  NULL ,'
         +'    TYPE_MEMO VARCHAR (50)  NULL ,'
         +'    TYPE_ORDR INT NULL,'
         +'    NAME_LINK VARCHAR(100) NULL'
         +')';
end;

class function TSQLY.ADD_PK_GKX_CACH_DATA: string;
begin
  Result:='ALTER TABLE GKX_CACH_DATA ADD CONSTRAINT PK_GKX_CACH_DATA PRIMARY KEY (CACH_IDENTITY,CACH_IDEX)';
end;

class function TSQLY.ADD_PK_GKX_CORD: string;
begin
  Result:='ALTER TABLE GKX_CORD ADD CONSTRAINT PK_GKX_CORD  PRIMARY KEY (UNIT_LINK,CORD_IDEX)';
end;

class function TSQLY.ADD_PK_GKX_GKJG: string;
begin
  Result:='ALTER TABLE GKX_GKJG ADD CONSTRAINT PK_GKX_GKJG PRIMARY KEY (UNIT_LINK,GKJG_IDEX)';
end;

class function TSQLY.ADD_PK_GKX_GKJG_FL: string;
begin
  Result:='ALTER TABLE GKX_GKJG_FL ADD CONSTRAINT PK_GKX_GKJG_FL PRIMARY KEY (UNIT_LINK,GKJG_IDEX,GKJG_FLID)';
end;

class function TSQLY.ADD_PK_GKX_GKJL: string;
begin
  Result:='ALTER TABLE GKX_GKJL ADD CONSTRAINT PK_GKX_GKJL PRIMARY KEY (UNIT_LINK,GKJG_IDEX,GKJL_IDEX)';
end;

class function TSQLY.ADD_PK_GKX_GKJL_EL: string;
begin
  Result:='ALTER TABLE GKX_GKJL_EL ADD CONSTRAINT PK_GKX_GKJL_EL PRIMARY KEY (GKJG_IDEX, UNIT_LINK, GKJL_IDEX, GKJL_FLID)';
end;

class function TSQLY.ADD_PK_GKX_GKJL_FL: string;
begin
  Result:='ALTER TABLE GKX_GKJL_FL ADD CONSTRAINT PK_GKX_GKJL_FL PRIMARY KEY (GKJG_IDEX, UNIT_LINK, GKJL_IDEX, GKJL_FLID, GKJG_FLID)';
end;

class function TSQLY.ADD_PK_GKX_TYPE: string;
begin
  Result:='ALTER TABLE GKX_TYPE ADD CONSTRAINT GKX_TBL_TYPE  PRIMARY KEY (UNIT_LINK,CORD_IDEX,TYPE_IDEX)';
end;

class function TSQLY.UPDATE_GKX_GKJG_SET_PKEY_CHCK_EQUAL_ONE: string;
begin
  Result:='UPDATE GKX_GKJG SET PKEY_CHCK =1';
end;

end.
